package cn.edu.ctbu.lddweb.service.lmpl;

import cn.edu.ctbu.lddweb.mapper.StudentMapper;
import cn.edu.ctbu.lddweb.pojo.Student;
import cn.edu.ctbu.lddweb.service.StudentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生管理实现层
 */
@Service
public class StudentServicelmpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectList(Student student) {
        return studentMapper.selectList(student);
    }

    /**
     * 检查是否唯一（允许学生重名，但是，一个班级里面不能存在两个相同姓名、性别的学生！！！）
     * @param student
     * @return
     */
    @Override
    public Boolean checkStudentUnique(Student student) {
        int id = student.getId()==0?-1:student.getId();
        Student info = studentMapper.checkStudentUnique(student);
        if(info!=null&&info.getId()!=id){
            return true;
        }
        return false;
    }

    @Override
    public Student findID(@Param("id") int id) {
        return studentMapper.findID(id);
    }

    @Override
    public int insertStudent(Student student) {
        return studentMapper.insertStudent(student);
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public int deleteStudent(String id) {
        return studentMapper.deleteStudent(id);
    }

    @Override
    public int updatePerson(Student student) {
        return studentMapper.updatePerson(student);
    }
}
